type Handler = {
    setNext: (handler: Handler) => Handler;
    handle: (request: number) => string;
  };
  
  function handleRequest(request: number): string {
    const handler1: Handler = {
      setNext: (handler: Handler): Handler => {
        this.nextHandler = handler;
        return handler;
      },
      handle: (request: number): string => {
        if (request < 0) {
          return "负数";
        }
        if (this.nextHandler) {
          return this.nextHandler.handle(request);
        }
        return "正数";
      },
    };
  
    const handler2: Handler = {
      setNext: (handler: Handler): Handler => {
        this.nextHandler = handler;
        return handler;
      },
      handle: (request: number): string => {
        if (request % 2 === 0) {
          return "偶数";
        }
        if (this.nextHandler) {
          return this.nextHandler.handle(request);
        }
        return "奇数";
      },
    };
  
    handler1.setNext(handler2);
    return handler1.handle(request);
  }
  
  handleRequest(3); // 奇数
  handleRequest(-1); // 负数
  handleRequest(4); // 偶数